home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABResource.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  6.0 KB  |  264 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABResource.c
  15.  
  16. NAME
  17.     ABResource.c, part of the ABox project source code,
  18.     responsible for handling the AboutBox resource (element) class stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     9 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  38.                             release and the associated Universal Headers from Apple:
  39.                             most methods that returned references now have "Ref" at
  40.                             the end of their methods names to prevent possible collisions
  41.                             with datatypes and classes of the same name (older versions
  42.                             of the compiler didn't have a problem with this).
  43.  
  44. */
  45.  
  46. /*===========================================================================*/
  47.  
  48. /*======= Segmentation directives ========*/
  49.  
  50. #ifdef USE_MANUAL_SEGMENTATION
  51. #pragma segment ty
  52. #endif
  53.  
  54. /*============ Header files ==============*/
  55.     
  56. #include     "ABResource.h"
  57.  
  58. /*=============== Globals ================*/
  59.  
  60. /*================ CODE ==================*/
  61.  
  62.  
  63. /*=============================== ABResource::ABResource ================================*/
  64. ABResource::ABResource(void)
  65. {
  66.     mResType = kABbadResourceType;
  67.     mResID = 0;
  68.     mResHandle = NULL;
  69. } // end ABResource
  70.  
  71.  
  72.  
  73. /*=============================== ABResource::~ABResource ================================*/
  74. ABResource::~ABResource(void)
  75. {
  76.     this->ReleaseResource();
  77.  
  78. } // end ~ABResource
  79.  
  80.  
  81.  
  82. /*=============================== ABResource::ReleaseResource ================================*/
  83. OSErr
  84. ABResource::ReleaseResource(void)
  85. {
  86.     OSErr error = noErr;
  87.     
  88.     if (this->ResourceHandleRef())
  89.     {
  90.         ::ReleaseResource(this->ResourceHandleRef());
  91.         this->ResourceHandleRef() = NULL;
  92.         error = ::ResError();
  93.     } 
  94.     return error;
  95.     
  96. } // end ReleaseResource
  97.  
  98.  
  99.  
  100. /*=============================== ABResource::CheckFile ================================*/
  101. Boolean    ABResource::CheckFile(FSSpecPtr fssptr)
  102. {
  103.     OSErr        error = noErr;
  104.     Boolean        fileOK = false;
  105.     short        oldRefNum = CurResFile();
  106.     short        resRefNum;
  107.     
  108.     //    begin here...
  109.     //
  110.     if (fssptr) 
  111.     {
  112.         //    the caller specified a file to use
  113.         resRefNum = ::FSpOpenResFile (fssptr, fsRdPerm);
  114.         error = ResError();
  115.         if (error) 
  116.         {
  117.             ::UseResFile (oldRefNum);
  118.             return false;
  119.         } else {
  120.             ::UseResFile (resRefNum);
  121.         } // end if else block
  122.     } // end if block
  123.  
  124.     this->ResourceHandleRef() = ::Get1Resource (this->ResourceTypeRef(), this->ResID());
  125.     error = ::ResError();
  126.     if (this->ResourceHandleRef() && !error)
  127.         fileOK = true;
  128.     else
  129.         fileOK = false;
  130.  
  131.     if (fssptr) 
  132.     {
  133.         ::CloseResFile(resRefNum);
  134.         ::UseResFile (oldRefNum);
  135.     } // end if block
  136.         
  137.  
  138.     return fileOK;
  139. } // end CheckFile
  140.  
  141.  
  142.  
  143.  
  144. /*=============================== ABResource::Stop ================================*/
  145. OSErr    ABResource::Stop(void)
  146. {
  147.     //    begin here...
  148.     //
  149.     //    subclasses can OVERRIDE this method if they wish, but the intent
  150.     //    here is to halt whatever is going on and free things up if at all possible
  151.     //
  152.     return this->ReleaseResource();
  153.     
  154. } // end Stop
  155.  
  156.  
  157.  
  158.  
  159. /*=============================== ABResource::Initialize ================================*/
  160. OSErr    ABResource::InitializeResource(void)
  161. {
  162.     OSErr        error = noErr;
  163.     
  164.     //    begin here...
  165.     //
  166.     //    subclasses can override this method if they wish, but the intent
  167.     //    here is to perform whatever resource loading/initialize might
  168.     //    be required for the object.
  169.     //
  170.     if (this->DoesntHaveResourceHandleRef())
  171.     {
  172.         this->ResourceHandleRef() = ::GetResource (this->ResourceTypeRef(), this->ResID());   /* IM I pg 119 */
  173.         error = ::ResError();
  174.     } else {
  175.         ::LoadResource(this->ResourceHandleRef());
  176.         error = ::ResError();
  177.     } // end if block
  178.     
  179.     if (this->HasResourceHandleRef())
  180.         ::HNoPurge(this->ResourceHandleRef());
  181.         
  182.     error = ::ResError();
  183.     return error;
  184. } // end InitializeResource
  185.  
  186.  
  187.  
  188.  
  189. /*=============================== ABResource::GetProperty ================================*/
  190. OSErr    ABResource::GetProperty(ABProperty prop, 
  191.                                 void *ptr, 
  192.                                 long *ptrSize)
  193. {
  194.     OSErr    error = noErr;
  195.     long    pSize;
  196.     
  197.     //    begin here...
  198.     
  199.     if (!ptr)
  200.         return kABPropertyNullStorage;
  201.     
  202.     switch (prop)
  203.     {
  204.         case    kABResourceResType:
  205.                     (*(ResType *)ptr) = this->ResourceTypeRef();
  206.                     pSize = kABResourceResTypeSize;
  207.                     break;
  208.         case    kABResourceResID:
  209.                     (*(short *)ptr) = this->ResID();
  210.                     pSize = kABResourceResIDSize;
  211.                     break;
  212.         case    kABResourceHandle:
  213.                     error = this->InitializeResource();
  214.                     (*(Handle *)ptr) = this->ResourceHandleRef();
  215.                     pSize = kABResourceHandleSize;
  216.                     break;
  217.         default:
  218.                     error = kABResourceSuperProperty::GetProperty(prop, ptr, ptrSize);
  219.                     break;
  220.     } // end switch block
  221.     
  222.     if (ptrSize && !error)
  223.         *ptrSize = pSize;
  224.     return error;
  225.     
  226. } // end GetProperty
  227.  
  228.  
  229.  
  230. /*=============================== ABResource::SetProperty ================================*/
  231. OSErr    ABResource::SetProperty(ABProperty prop, 
  232.                                 void *ptr, 
  233.                                 long ptrSize)
  234. {
  235.     OSErr    error = noErr;
  236.     
  237.     //    begin here...
  238.     
  239.     if (!ptr)
  240.         return kABPropertyNullStorage;
  241.     
  242.     switch (prop)
  243.     {
  244.         case    kABResourceResType:
  245.                     this->ResourceTypeRef() = (*(ResType *)ptr);
  246.                     break;
  247.         case    kABResourceResID:
  248.                      this->ResID() = (*(short *)ptr);
  249.                     break;
  250.         case    kABResourceHandle:
  251.                     this->ResourceHandleRef() = (*(Handle *)ptr);
  252.                     break;
  253.         default:
  254.                     error = kABResourceSuperProperty::SetProperty(prop, ptr, ptrSize);
  255.                     break;
  256.     } // end switch block
  257.     
  258.     return error;
  259.     
  260. } // end SetProperty
  261.  
  262.  
  263.  
  264. //    end of file.